/**
 * This class represents the Wagon object, and has a Pace attribute
 *
 * @author Akbar Dhannani
 * @version 1.0.0.0
 */
public class Wagon {
	private Pace pace;
	private Settler[] people;
	private Player player;
	private static Wagon singletonWagon;
	private static InventoryController invControl;



	/**
	 * The constructor creates an array of Settle objects and adds 4 settler objects to it
	 * It also sets the initial pace of the wagon
	 * @param one Settler one
	 * @param two Settler two
	 * @param three Settler three
	 * @param four Settler four
	 * @param pace Pace of the wagon
	 * A private Constructor prevents any other class from instantiating the Singleton. 
	 */
	private Wagon(Object one,Object two,Object three,Object four, Pace pace, Player player){
		people = new Settler[4];
		people[0] = (Settler)one;
		people[1]= (Settler)two;
		people[2]= (Settler)three;
		people[3]=(Settler)four;
		this.player = player;
		this.pace = pace;
		int money = 0;
		if(player.profession.equals(Profession.FARMER)){
			money = 400;
		}
		if(player.profession.equals(Profession.CARPENTER)){
			money = 800;
		}
		if(player.profession.equals(Profession.BANKER)){
			money = 1600;
		}
		this.invControl = new InventoryController(money);
	}

	public static synchronized Wagon getWagon(Object one,Object two,Object three,Object four, Pace pace, Player player) {
		if (singletonWagon == null) {
			singletonWagon = new Wagon(one, two, three, four, pace, player);
		}
		return singletonWagon;
	}

	public static synchronized Wagon getWagon() {
		return singletonWagon;
	}
	public Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException();
	}


	/*
	 * Returns a string representation of the data stored in the wagon
	 * @return A string holding the data stored in the wagon. 
	 */
	public String toString(){
		String str = "";
		str += "Settler names and rations: ";
		for(Settler curr: people){
			str += "Setter: " + curr.getName() + " Ration: " + curr.getRation() + "\n";
		}
		str += "Pace: " + pace;
		str += "\nPlayer data: " + player.getName() + " Ration:" + player.getRation() + " Profession" + player.getProfession();
		return str;
	}

	/**
	 * Getter method for the player
	 * @return The player in the wagon
	 */
	public Player getPlayer(){
		return player;
	}

	/**
	 * Getter method for the array of settlers
	 * @return The array of settlers in the wagon
	 */
	public Settler[] getPeople(){
		return people;
	}

	/**
	 * Getter method for the pace
	 * @return The current pace of the journey
	 */
	public Pace getPace(){
		return pace;
	}

	/**
	 * Setter method for the pace
	 * @param pace The desired pace for the journey
	 */
	public void setPace(Pace pace){
		this.pace = pace;
	}
	
	/**
	 * Getter for the inventory controller
	 * @return 
	 */
	public static InventoryController getInventoryController(){
		return invControl;
	}
	
	/**
	 * Getter for the first settler in the party
	 * @return The first settler
	 */
	public Settler getSettlerOne(){
		return people[0];
	}

	/**
	 * Getter for the second settler in the party
	 * @return The second settler
	 */
	public Settler getSettlerTwo(){
		return people[1];
	}
	
	/**
	 * Getter for the third settler in the party
	 * @return The third settler
	 */
	public Settler getSettlerThree(){
		return people[2];
	}
	
	/**
	 * Getter for the fourth settler in the party
	 * @return The fourth settler
	 */
	public Settler getSettlerFour(){
		return people[3];
	}
}


